#include "10_19_test.h";
#include <iostream>
using namespace std;
void QueueInit(Queue* pq)
{
	if (pq == NULL)
	{
		exit(-1);
	}
	pq->head = NULL;
	pq->tail = NULL;
}
void QueuePush(Queue* pq, QDataType x)
{
	if (pq == NULL)
	{
		exit(-1);
	}
	QueueNode* newnode = (QueueNode*)malloc(sizeof(QueueNode));
	if (newnode == NULL)
	{
		cout << "malloc fail" << endl;
		exit(-1);
	}
	newnode->data = x;
	newnode->next = NULL;
	if (pq->head == NULL && pq->tail == NULL)
	{
		pq->head = pq->tail = newnode;
	}
	else
	{
		pq->tail->next = newnode;
		pq->tail = newnode;
	}
}
void QueuePop(Queue* pq)
{
	if (pq == NULL) exit(-1);
	if (QueueEmpty(pq))
	{
		exit(-1);
	}
	else
	{
		QueueNode* next = pq->head->next;
		free(pq->head);
		pq->head = next;
		if (pq->head == NULL)
		{
			pq->tail = NULL;
		}
	}
}
QDataType QueueFront(Queue* pq)
{
	if (pq == NULL) exit(-1);
	return pq->head->data;
}

int QueueSize(Queue* pq)
{
	if (pq == NULL) exit(-1);
	QueueNode* cur = pq->head;
	int i = 0;
	while (cur != NULL)
	{
		cur = cur->next;
		i++;
	}
	return i;
}

bool QueueEmpty(Queue* pq)
{
	if (pq == NULL) exit(-1);
	return pq->head == NULL;
}